package book.dao.impl;

import book.dao.IBookDao;
import book.entity.Book;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/3/30/030.
 */

@Repository
public class BookDaoImpl extends JdbcDaoSupport implements  IBookDao {
    @Override
    public int addBook(Book book) {
        String sql="insert into book(bname,bprice) values (?,?)";
        getJdbcTemplate().update(sql,book.getbName(),book.getbPrice());
        return getJdbcTemplate().update(sql,book.getbName(),book.getbPrice());
    }

    @Override
    public List<Book> bookList() {
        String sql="select * from book";
        return  getJdbcTemplate().query(sql,new BookRowMap());
    }

    @Resource
    public void setJdbcTemplate1(JdbcTemplate jdbcTemplate){
        super.setJdbcTemplate(jdbcTemplate);
    }
}
